package com.twu.biblioteca;

public enum Action {
    BORROW(1, "Borrow Goods",false),
    RETURN(2, "Return Goods",false),
    USER_INFO(3, "Profile",false),
    QUERY(4,"Query the borrower",true);


    private final int actionIndex;
    private String displayValue;
    private boolean isLibririanPermission;

    private Action(int actionIndex, String displayValue, boolean isLibririanPermission) {
        this.actionIndex = actionIndex;
        this.displayValue = displayValue;
        this.isLibririanPermission = isLibririanPermission;
    }

    public int getActionIndex() {
        return actionIndex;
    }

    public String getDisplayValue() {
        return displayValue;
    }

    public static Action from(int index,boolean isLibririanPermission) {
        for (Action action : Action.values()) {
            if(isLibririanPermission==false&&action.isLibririanPermission==true){
                continue;
            }
            if (action.getActionIndex() == index) {
                return action;
            }
        }
        return null;
    }

    public boolean isLibririanPermission() {
        return isLibririanPermission;
    }
}
